/*
 ------------------------------------------------------------------------------
 Copyright (C) 2006-2007 Team Blur.

 This file is part of the Quantum Engine source code.

 The Quantum Engine source code is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or (at your
 option) any later version.

 The Quantum Engine source code is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 more details.

 You should have received a copy of the GNU General Public License along with
 the Quantum Engine source code; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 ------------------------------------------------------------------------------
*/


#ifndef __CG_PUBLIC_H__
#define __CG_PUBLIC_H__


#define CGAME_API_VERSION		2

// Functions exported by the game library
typedef struct {
	int						apiVersion;

	int						gameProtocol;

	// Writes a game state in the given message buffer.
	// Returns an offset that can be used in a subsequent call to this
	// function, or -1 if the entire game state has been written.
	// This is used for demo recording in the engine.
	int						(*WriteGameState)(int offset, ByteBuffer *msg);

	// Parses a game state from the server.
	// Returns an offset to request the remaining data, or -1 if the entire
	// game state has been parsed.
	// This is only used during the connection process, before loading the
	// level.
	int						(*ParseGameState)(ByteBuffer *msg);

	// Parses a snapshot from the server.
	// Returns true if the snapshot was valid.
	bool					(*ParseSnapshot)(int sequence, ByteBuffer *msg, int *time, bool *deltaCompressed);

	// Executes a string command from the server.
	// The string has been tokenized by the engine and the Cmd_* functions can
	// be used to retrieve the command arguments.
	void					(*ServerCommand)(void);

	// Runs prediction on the player and all the other entities
	void					(*RunFrame)(int time, const userCmd_t *userCmd);

	// Refreshes the game screen and audio
	void					(*Refresh)(void);

	// Loads the current level.
	// This will also be called after a client subsystem restart.
	void					(*LoadLevel)(void);

	// Frees the current level.
	// This will also be called before a client subsystem restart.
	void					(*FreeLevel)(void);

	// Initializes the game
	void					(*Init)(void);

	// Shuts down the game
	void					(*Shutdown)(void);
} cgExport_t;

// Functions imported from the engine
typedef struct {
	odMemory_t				odMemory;
	odFileSystem_t			odFileSystem;
	odCmdSystem_t			odCmdSystem;
	odCVarSystem_t			odCVarSystem;
	odParser_t				odParser;
	odSystem_t				odSystem;
	odCollision_t			odCollision;
	odRenderer_t			odRenderer;
	odSound_t				odSound;
	odEditor_t				odEditor;

	// Sets the delta angles sent by the server
	void					(*SetDeltaAngles)(const int deltaAngles[3]);

	// Sets the mouse view sensitivity scale factor
	void					(*SetSensitivity)(float sensitivity);

	// Pumps events and updates the screen to let the loading GUI refresh
	void					(*UpdateLoading)(void);
} cgImport_t;

// Game API prototype
typedef cgExport_t *		(*GETCGAMEAPI)(cgImport_t *);


#endif	// __CG_PUBLIC_H__
